#include<iostream>
using namespace std;
typedef long long LL;
int n, m;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int l, r;
		cin >> l >> r;
		LL sum = 0;
		for (int i = l; i <= r; i++) {
			sum += i;
		}
		cin >> m;
		while (m--) {
			int x;
			cin >> x;
			if (sum % x) {
				cout << 1 << endl;
			}
			else {
				cout << 0 << endl;
			}
		}
	}
	return 0;
}